#include "utils.h"

#include <openssl/md5.h>
#include <stdexcept>

namespace crawler { namespace server {
u_int64_t Utils::Md5Low64(const std::string &str) {
  if (str.empty()) {
    throw std::runtime_error("Utils::Md5Low64 cannot calculate id for "
                             "empty string");
  }
  unsigned char md[16];
  MD5((unsigned char *)str.data(), str.size(), md);
  u_int64_t id = *(u_int64_t*)md;

  return id;
}
}}

